package com.wys.proxydemo.common;

import com.wys.proxydemo.jdk.JDKChuShi;
import sun.misc.ProxyGenerator;

import java.io.FileOutputStream;

/**
 * @author godShan
 * @Description:
 * @date 2019/5/6 9:16
 */
public class Test {

    public static void main(String[] args) {

        //这个是使用 jdk动态代理厨师的案例
        Person person = (Person) new JDKChuShi().getInstance(new Son());
        System.out.println(person.eat("佛跳墙"));


        //输出一个jdk 生成的动态代理类
        try {
            byte[] bytes = ProxyGenerator.generateProxyClass("$Proxy0", new Class[] {Person.class});
            FileOutputStream fos = new FileOutputStream("D://$Proxy0.class");
            fos.write(bytes);
            fos.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}
